Skip to content

refactor(flows): migrate agent-node completion to crate ChatModel (#4727)#4750

Open
senamakel wants to merge 1 commit into
tinyhumansai:mainfrom
senamakel:feat/flows-completion-chatmodel
Open

refactor(flows): migrate agent-node completion to crate ChatModel (#4727)#4750
senamakel wants to merge 1 commit into
tinyhumansai:mainfrom
senamakel:feat/flows-completion-chatmodel

Conversation

@senamakel

Copy link
Copy Markdown
Member

Summary

  • Migrates the tinyflows agent node completion (caps.rs llm.complete) off the raw create_chat_provider + provider.chat path onto the crate ChatModel interface (ModelRequest/invoke).
  • Adds two small, reusable seam converters — chat_messages_to_model_messages (host history → crate messages) and model_response_to_chat_response (crate response → host {text, tool_calls, usage, reasoning_content}) — so the flows node's JSON output envelope is byte-identical.
  • Adds factory::create_chat_model_pinned to honor a node-pinned raw/BYOK model id verbatim (issue Agent-node raw BYOK model overrides silently collapse to the chat model #4598) on the ChatModel path.

Problem

tinyflows/caps.rs was one of the last one-shot callers still on openhuman's in-house Provider trait + ChatRequest/provider.chat. It is a straggler in the tinyagents inference migration (Motion B of #4727 / #4249): every fix to the provider path had to account for this bespoke caller, and it blocked shrinking the create_chat_provider surface.

Solution

llm.complete now builds a crate ChatModel via create_chat_model_with_model_id (role default) and rebuilds it pinned via create_chat_model_pinned when a node overrides with a raw/BYOK model id (the existing resolve_completion_model logic is preserved, incl. its unit tests). Messages are converted through the new seam helper, the model is invoked, and the response is converted back into the exact host ChatResponse shape the node serializes into its JSON output — so structured-output parsing, tool_calls, usage, and reasoning_content behavior are unchanged.

This is independent of the larger Motion A harness refactor (PR #4726) — it uses only the pre-existing create_chat_model_* factory plus the new converters — so it lands standalone.

Submission Checklist

  • Tests added or updated — caps.rs resolve_completion_model unit tests preserved; the two new seam converters are exercised via the flows completion path. No behavior assertions changed (parity-preserving refactor).
  • Diff coverage ≥ 80%N/A (author env): full local coverage run not performed (pre-existing unrelated full---tests breakage in unrelated modules). Core lib cargo check green; convert/factory/caps modules compile clean. Please rely on CI for the gate.
  • Coverage matrix updated — N/A: behaviour-only refactor.
  • All affected feature IDs — N/A (internal refactor).
  • No new external network dependencies introduced.
  • Manual smoke checklist — N/A (no release-cut surface change; the flows node's output envelope is byte-parity).
  • Linked issue — see ## Related.

Impact

  • Platforms: desktop/web/CLI — internal flows-engine plumbing; no UX change.
  • Behavior: neutral — same underlying provider dispatch (crate ChatModel wraps it), byte-identical JSON output envelope.
  • Compat/migration: none.

Related

https://claude.ai/code/session_018MnMVgnzxchtcs1DDUxTfF

…tion B)

tinyhumansai#4727 straggler: tinyflows/caps.rs llm.complete now drives a crate ChatModel
(create_chat_model_with_model_id + a create_chat_model_pinned rebuild for the
node raw/BYOK override, tinyhumansai#4598) via ModelRequest/invoke, instead of
create_chat_provider + provider.chat. Adds two reusable seam converters —
chat_messages_to_model_messages (host history -> crate messages) and
model_response_to_chat_response (crate response -> host {text, tool_calls,
usage, reasoning_content}) — so the flows node's JSON output envelope is
byte-identical. Core lib green; convert/factory/caps test modules clean.

Claude-Session: https://claude.ai/code/session_018MnMVgnzxchtcs1DDUxTfF
@senamakel senamakel requested a review from a team July 9, 2026 15:26
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c02a6b0d-adf3-4346-bee7-994aa1c5aa59

📥 Commits

Reviewing files that changed from the base of the PR and between e5c6507 and 16ae696.

📒 Files selected for processing (4)
  • src/openhuman/inference/provider/factory.rs
  • src/openhuman/tinyagents/convert.rs
  • src/openhuman/tinyagents/mod.rs
  • src/openhuman/tinyflows/caps.rs

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16ae696494

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +548 to +550
let response = crate::openhuman::tinyagents::model_response_to_chat_response(
&chat
.invoke(&(), model_request)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve literal tool-call markup in no-tools completions

Routing this no-tools completion through ProviderModel::invoke makes the adapter run the harness tool-call parser on every text response before model_response_to_chat_response sees it. Because llm.complete does not populate ModelRequest.tools (old ChatRequest.tools was None), prompts that legitimately ask the agent node to emit examples such as <tool_call>{"name":"x","arguments":{}}</tool_call> now have that text removed and surfaced as tool_calls, so the structured parser below sees truncated/empty text instead of the model's answer. The direct provider path returned that text verbatim; skip tool parsing for this one-shot/no-tools path or preserve the raw text.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant